﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharpHelpers.Sockets
{
    /// <summary>
    /// Socket基类
    /// </summary>
    public class SocketBase
    {
        protected string m_ServerIP = "127.0.0.1";
        protected string m_TavleID = "11001";
        protected int m_ServerPort = 11801;

        protected byte[] m_header;
        protected int MESSAGE_HEADER_SIZE = 8;
        protected int MESSAGE_HEADER_MARK;
        protected int MAX_MESSAGE_SIZE = 1024;
        protected int RECEIVED_BUFFER_LEN = 4096;
        protected byte[] MESSAGE_BUFFER = new byte[4096];

        protected int m_ReconnectTimes = 0;
        protected int m_ReceivedBufferOffset = 0;
        protected int ReConnectCounter = 0;
        protected bool m_IsConnected = false;
        protected bool m_HaveShowConnecting = false;

        public SocketBase()
        {
            // 0~3: mark,
            // 4~7: 整條消息長度
            // 8~11: 加密消息長度.
            // 12~n：內容
            m_header = new byte[8];

            //0~3: mark,
            m_header[0] = 0x98;
            m_header[1] = 0x87;
            m_header[2] = 0x79;
            m_header[3] = 0x98;

            //4~7: 整條消息長度
            m_header[4] = 0x00;
            m_header[5] = 0x00;
            m_header[6] = 0x00;
            m_header[7] = 0x00;
            MESSAGE_HEADER_MARK = SocketBufferHelper.GetMessageMark(m_header, 0);
            MESSAGE_HEADER_SIZE = 8;
        }
    }
}
